﻿using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SaunaClient.Model.Logger
{
    /// <summary>
    /// Console Logger class that outputs a log message to console
    /// </summary>
    /// <remarks>
    /// This class is thread safe. 
    /// </remarks>
    /// <dates>
    /// 15/05/2011 - created by Chiaki Sato
    /// </dates>
    public class ConsoleLogger : ILogger
    {
        private ILoggerMessage stackTraceMessage;
        private ILoggerMessage hostAddressMessage;
        public enum LogType { UNIT = 1, COMPO = 2 }

        /// <summary>
        /// Default constructor for ConsoleLogger class.
        /// </summary>
        public ConsoleLogger(LogType logType)
        {
            stackTraceMessage = new StackTraceMessage((StackTraceMessage.LogType)logType);
            hostAddressMessage = HostAddressSingleton.Instance;
        }

        /// <summary>
        /// Display a log message with the host address and stack trace to console
        /// </summary>
        /// <param name="message">User log message</param>
        /// <remarks>
        /// From MSDN: Console class is thread safe. Thus, Console.WriteLine() is also thread safe. 
        /// </remarks>
        public string Write(string message)
        {
            string logMessage = hostAddressMessage.CreateLogMessage()
                              + stackTraceMessage.CreateLogMessage()
                              + message;
            Console.WriteLine(logMessage);

            return logMessage;
        }
    }
}
